#!/bin/bash

# a very simple script to start a bunch of screen windows, with zero error checking

if [ -z $1 ]; then
  echo "Please specify a name for your screen session as an argument to this script."
  exit
fi

IS_SCREEN=`screen -list | grep $1`

if [ -z "$IS_SCREEN" ]; then
  screen -d -m -S $1
  screen -X -S $1 screen -t run
  screen -X -S $1 screen -t shell 
  screen -X -S $1 screen -t python
  screen -X -S $1 screen -t test
  screen -X -S $1 screen -t templates
  screen -X -S $1 screen -t core
  screen -X -S $1 screen -t coretempl
  screen -X -S $1 screen -t ext
  screen -X -S $1 screen -t exttempl

  screen -X -S $1 -p 0 stuff "exit
" 
  screen -X -S $1 screen -t deploy

  MANAGE=`ls manage.py`
  SETTINGS=`ls settings.py`
  if [ $MANAGE == "manage.py" -a $SETTINGS == "settings.py" ]; then
    screen -X -S $1 -p 1 stuff "python manage.py runserver;
"
    screen -X -S $1 -p 2 stuff "clear
"
    screen -X -S $1 -p 3 stuff "python manage.py shell;
"
    screen -X -S $1 -p 4 stuff "python manage.py test pirate_extensions;
"
    screen -X -S $1 -p 5 stuff "cd templates;
"
    screen -X -S $1 -p 6 stuff "cd pirate_core;
"
    screen -X -S $1 -p 7 stuff "cd pirate_core/templatetags;
"
    screen -X -S $1 -p 8 stuff "cd pirate_extensions;
"
    screen -X -S $1 -p 9 stuff "cd pirate_extensions/templatetags;
"
  fi

  for i in 2 2 3 4 5 6 7 8
  do
    screen -X -S $1 select $i
  done
fi

screen -x $1 -p 0
